﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using System.Web.UI.WebControls;
using System.Data;

/// <summary>
/// Summary description for util
/// </summary>
public class util
{
	public util()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public static string DATACONNECTION
    {
        get { return System.Configuration.ConfigurationSettings.AppSettings["dataconn"]; }
    }
    public static string GetResponseAlert(string strText)
    {
        return string.Format("<script>alert('{0}')</script>", strText);
    }

    public static string GetShowName(string strtable,string strid)
    {
        string strsql = string.Format("SELECT [id], [showname] FROM [{0}] where [id]='{1}'", strtable, strid);
        ManageData md = new ManageData(util.DATACONNECTION);
        if (md != null)
        {
            DataSet ds = md.ExecDS(strsql);
            if (ds != null && ds.Tables.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {

                    return dr["showname"].ToString();
                }
            }
        }

        return "";

    }

    public static void CreateDownList(DropDownList dd, string strtable)
    {
        dd.Items.Clear();
        string strsql = string.Format("SELECT [id], [showname] FROM [{0}]", strtable);
        ManageData md = new ManageData(util.DATACONNECTION);
        if (md != null)
        {
            DataSet ds = md.ExecDS(strsql);
            if (ds != null && ds.Tables.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {

                    ListItem li = new ListItem(dr["showname"].ToString(), dr["id"].ToString());

                    dd.Items.Add(li);
                }
            }
        }
    }

    public static void CreateDownListWithQuanBu(DropDownList dd, string strtable)
    {
        dd.Items.Clear();

        ListItem li1 = new ListItem("全部", "0");
        dd.Items.Add(li1);
        string strsql = string.Format("SELECT [id], [showname] FROM [{0}]", strtable);
        ManageData md = new ManageData(util.DATACONNECTION);
        if (md != null)
        {
            DataSet ds = md.ExecDS(strsql);
            if (ds != null && ds.Tables.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {

                    ListItem li = new ListItem(dr["showname"].ToString(), dr["id"].ToString());

                    dd.Items.Add(li);
                }
            }
        }
    }


    public static void CreateDownListSpVal(DropDownList dd, string strtext,string strval)
    {
        ListItem li1 = new ListItem(strtext, strval);
        dd.Items.Add(li1);               
    }





   
}
